package com.zcy.basic.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * <p>
 *  统一返回结果
 * </p>
 *
 * @author lucker
 * @date 2023/11/28 19:26
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "统一响应格式", description = "AjaxResult")
public class AjaxResult {
    @ApiModelProperty("响应数据")
    private Object data;

    @ApiModelProperty("响应信息")
    private String msg;

    @ApiModelProperty("响应是否成功")
    private Boolean success;

    public static AjaxResult success() {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(Boolean.TRUE);
        ajaxResult.setMsg("操作成功");
        return ajaxResult;
    }

    public static AjaxResult success(String msg) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(Boolean.TRUE);
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }

    public static AjaxResult success(Object data) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(Boolean.TRUE);
        ajaxResult.setData(data);
        ajaxResult.setMsg("操作成功");
        return ajaxResult;
    }

    public static AjaxResult success(Object data, String msg) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(Boolean.TRUE);
        ajaxResult.setData(data);
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }

    public static AjaxResult error() {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(Boolean.FALSE);
        ajaxResult.setMsg("操作失败");
        return ajaxResult;
    }


    public static AjaxResult error(String msg) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(Boolean.FALSE);
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }

    public static AjaxResult error(Object data, String msg) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setData(data);
        ajaxResult.setSuccess(Boolean.FALSE);
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }


}
